package cn.kgc.itrip.biz.controller;

import cn.kgc.itrip.beans.dto.Dto;
import cn.kgc.itrip.beans.pojo.ItripAreaDic;
import cn.kgc.itrip.beans.vo.ItripAreaDicVO;
import cn.kgc.itrip.biz.service.AreaDicService;
import cn.kgc.itrip.utils.DtoUtil;
import cn.kgc.itrip.utils.ErrorCode;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/api/hotel")
public class HotelController {

    @Resource
    private AreaDicService areaDicService;

    /**
     * 查询热门 城市
     */
    @RequestMapping(value = "/queryhotcity/{isChina}",method = RequestMethod.GET)
    public Dto doQueryHotCity(@PathVariable String isChina){
        try {
            // 查询信息
            List<ItripAreaDic> areaDics = areaDicService.getHotCity(isChina);
            // 转换
            List<ItripAreaDicVO> vos = new ArrayList<>();
            for (ItripAreaDic areaDic : areaDics) {
                ItripAreaDicVO vo = new ItripAreaDicVO();
                BeanUtils.copyProperties(areaDic,vo);
                vos.add(vo);
            }

            return DtoUtil.returnDataSuccess(vos);
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("查询热门城市失败！", ErrorCode.BIZ_UNKNOWN);
        }
    }
}
